﻿//form input style changed

var  focusobj= null;

function  mouseoverinput( inputobj)
{
    inputobj.className = "focus";
}
function  mouseoutinput( inputobj)
{
    if ( inputobj != focusobj)
	inputobj.className = "";
}

function setCheckboxField(fieldName){
    //var chkField = document.getElementsByName('Checkbox_' + fieldName)[0];
    //alert(document.getElementsByName('Checkbox_' + fieldName).length);
    //var vField   = document.getElementsByName('Field_' + fieldName)[0];
    //zhangbo 2005-10-10
    var chkField = document.getElementById('Checkbox_' + fieldName);
    var vField   = document.getElementById('Field_' + fieldName);
    if(chkField.checked == true){
      vField.value = 'true';
    }
    else{
      vField.value = 'false';
    }
}

//将RadioButton数据项类型使用隐藏域实现，因为radio控件在没有选中的情况下，
//自身的名称不会向后台提交，而这会影响一些功能的实现

  function setMultiboxForm(fieldName){
    var checkboxs = document.getElementsByName('Multibox_' + fieldName);
    var vField   = document.getElementsByName(fieldName)[0];
    var curValue = '';
    var i = 0 ;
    var j = 0;
    var length = checkboxs.length;
    for(i = 0 ; i < length ; i++){
        if(checkboxs[i].checked == true){
           if(j == 0){
              curValue = checkboxs[i].value;
           }
           else{
              curValue = curValue + ',' + checkboxs[i].value;
           }
           j++;
        }
    }
    vField.value = curValue;
}

function setRadioButtonField(fieldName){
    var radioButtons = document.getElementsByName('RadioButton_' + fieldName);
    var vField   = document.getElementsByName('Field_' + fieldName)[0];
    var curValue = '';
    var length = radioButtons.length;
    for(var i = 0 ; i < length ; i++){
        if(radioButtons[i].checked == true){
           curValue = radioButtons[i].value;
           break;
        }
    }
    vField.value = curValue;	
}

function setMultiboxField(fieldName){
    var checkboxs = document.getElementsByName('Multibox_' + fieldName);
    var vField   = document.getElementsByName('Field_' + fieldName)[0];
    var curValue = '';
    var i = 0 ;
    var j = 0;
    var length = checkboxs.length;
    for(i = 0 ; i < length ; i++){
        if(checkboxs[i].checked == true){
           if(j == 0){
              curValue = checkboxs[i].value;
           }
           else{
              curValue = curValue + ',' + checkboxs[i].value;
           }
           j++;
        }
    }
    vField.value = curValue;
}

function doLockTask(value) {
	// 对于申请任务和放弃任务不需要confirm
	if(!userClicked){
  		document.activityForm.method.value = value;
  		document.activityForm.fireEvent("onsubmit");
  		document.activityForm.submit();
  	  	userClicked = true;
	  	BeginShowWaiting(window.event);    
  	 }   
}

function doTransfer(doit, processId, processLabel, needConfirm) {
	if(!userClicked){
		var msg = "委托";
		if (doit == "Transfer") msg = "转交";
		if(doConfirm('确定要'+msg+'吗?', needConfirm)){
			document.location = 'ActivityForm.do?method=showTransferForm&id='+processId +'&processlabel=' + processLabel + '&transferType=' + doit;
			userClicked = true;
	  		BeginShowWaiting(window.event);
	  	}
	}
}


function doRandomProc(processId, needConfirm) {
	if(!userClicked){
		if(doConfirm('确定要启动不定流程吗?', needConfirm)){
			document.location = 'ActivityForm.do?method=showRandomProcForm&id='+processId;
			userClicked = true;
	  		BeginShowWaiting(window.event);
	  	}
	}
}

function doExternalProc(processId, needConfirm) {
	if(!userClicked){
		if(doConfirm('确定要调用外部流程吗?', needConfirm)){
			document.location = 'ActivityForm.do?method=showExternalProcSel&id='+processId;
			userClicked = true;
	  		BeginShowWaiting(window.event);
	  	}
	}
}

// 下面代码中调用的setAttachHiddenFieldValue()，checkRequireValueIframes()
// 与附件管理相关，需要在jsp页面中动态生成这两个函数
function saveForm(srcformName) {
	var srcform = document.getElementById(srcformName);
	if(!userClicked){
		setAttachHiddenFieldValue();
		if(!checkRequireValueIframes()){
    		return;
    	}
    	srcform.method.value = "saveForm";
    	srcform.fireEvent("onsubmit");
    	srcform.submit();
    	userClicked = true;
		BeginShowWaiting(window.event); 
		  
		// 判断是否为启动表单且是弹出式的表单，若是，则点击“暂存”时关闭当前页，父页面跳转到草稿箱列表页面。  
		if (srcformName=="startForm")
		{
			if(window.opener)
			{
				window.opener.location.href = contextPath + "/BufferedAction.do?method=listAllBufferedProcess";
			}
		}
  	}
  	     
}

function resetForm(srcformName) {
	var srcform = document.getElementById(srcformName);
	srcform.reset();
  	 //reset以后需要再设置一次和attachment相关的hidden域.
  	setAttachHiddenFieldValue();
}


var userClicked = false;
function submitFormA(value, srcformName, needConfirm) 
{
	var srcform = document.getElementById(srcformName);
	if (!checkOverride()) return;
    if (!userClicked){
    	///if (doConfirm('确定要'+value+'吗?', needConfirm)) {
			srcform.decisionStatusLabel.value=value;
	  		srcform.method.value = "submitForm";

	  		if(!checkRequireValueIframes()){
	    		return;
	      	}

	     	setAttachHiddenFieldValue();

			//表单需要验证
			if(srcform.formSignedValue != null ){
				var signedValue = srcform.formSignedValue.value;
				if(getDefaultCertificate(signedValue)==null){
				  alert("没有证书，请检查用户名");
				  return false;
				}else{
				  srcform.formSignedValue.value=signAndEnvelopData(getDefaultCertificate(signedValue),signedValue);				  
				}
			}

			//srcform.fireEvent("onsubmit");
			srcform.onsubmit;

	  	 	srcform.submit(); 

	  	 	userClicked = true;
	  	 	BeginShowWaiting(window.event);

			//为提示下一步处理人准备数据，流程id和流程名称
			if(document.getElementById("msgProcessId") && document.getElementById("msgProcessName")){				
				msgProcessId = document.getElementById("msgProcessId").value;			
				msgProcessName = document.getElementById("msgProcessName").value;
				if (typeof(parent.sendNextActionACLMsg)=="function") {
					parent.sendNextActionACLMsg(msgProcessId,msgProcessName,"0");
				}
			}
		
	  	//}
  	 } else {
  	   return false;
  	 }    
}

// 下面的函数可在实际页面重新定义覆盖
function checkOverride() {
	return true;
}

function revert(id) {    
	if(!userClicked){
        var resultString = showModalDialog(
    		"Revert.do?method=showRevertSettings&id="+id, document, 
    		"dialogWidth=350px;dialogHeight=280px;status=no;scroll=no");
        if (resultString!=null) {
            revertSettings = resultString.split("|");
            activityForm.action=
              'Revert.do?method=startRevert&srcId=' + id + '&targetId=' + 
              revertSettings[0] + '&gobackDirectly=' + revertSettings[1] + '&userOpinion=' + revertSettings[2];
            activityForm.fireEvent("onsubmit");
            activityForm.submit();
            userClicked = true;
            BeginShowWaiting(window.event);
			return true;
        }
    }
	return false;
}

function revertPrevious(id){
	if(!userClicked){
		var resultString = showModalDialog(
			"Revert.do?method=showRevertPrevSettings&id="+id,document,
			"dialogWidth=350px;dialogHeight=240px;status=no;scroll=no");
		if(resultString!=null){
			revertSettings = resultString.split("|");
			activityForm.action=
				'Revert.do?method=startRevertToPrevActivity&id='+id+
				'&userOpinion='+revertSettings[0];
			activityForm.fireEvent("onsubmit");
			activityForm.submit();
			userClicked=true;
			BeginShowWaiting(window.event);
			return true;
		}
	}
	return false;
}

function withdraw(id, srcformName) {
    
    if(!userClicked){
        var resultString = showModalDialog(
    		contextPath + "/WithDraw.jsp", document, 
    		"dialogWidth=350px;dialogHeight=200px;status=no");    		
        if (resultString!=null) {
            withdraws = resultString.split("|");
            if (null == srcformName)
            	srcformName = "activityForm";

            var srcform = document.getElementById(srcformName);
            
            srcform.action=contextPath + '/Withdraw.do?method=withdraw&id=' + id + '&userOpinion=' + withdraws[0];
            srcform.fireEvent("onsubmit");
            srcform.submit();
            userClicked = true;
            BeginShowWaiting(window.event);
        }
	}
}

// 增加暂停流程/活动函数
function doSuspendProcess(id, needConfirm){
	if(doConfirm("确认要暂停此活动吗?", needConfirm)){
		activityForm.action="SuspendProcess.do?method=showForm&isFromActivityList=true&id="+id;
		activityForm.submit();
		BeginShowWaiting(window.event);
	}
}

// 
function doResumeProcess(id, needConfirm){
	if(doConfirm("确认要恢复此活动的执行吗?", needConfirm)){
		activityForm.action="SuspendProcess.do?method=resumeProcess&id="+id;
		activityForm.submit();
		BeginShowWaiting(window.event);
	}
}

//增加常用语功能
var intDelay=0; 
var intInterval=5; 

function OpinionMenuClick(layerMenuName){
	//alert("window.event.x:"+window.event.x+"\nwindow.event.y:"+window.event.y+"\nevent.clientX:"+event.clientX+"\nevent.clientY:"+event.clientY+"\nevent.offsetX:"+event.offsetX+"\nevent.offsetY:"+event.offsetY+"\nwindow.event.screenX:"+window.event.screenX+"\nwindow.event.screenY:"+window.event.screenY);
	mov(layerMenuName);
	if (document.getElementById(layerMenuName).style.display=="") { 
		GradientClose(layerMenuName);
	} else { 
		document.getElementById(layerMenuName).filters.alpha.opacity=0; 
		document.getElementById(layerMenuName).style.display=""; 
		GradientShow(layerMenuName);
	} 
}

function HideOpinionMenu(layerMenuName){
	GradientClose(layerMenuName);
}

function ShowOpinionMenu(layerMenuName){
	mov(layerMenuName);
	document.getElementById(layerMenuName).filters.alpha.opacity=0; 
	document.getElementById(layerMenuName).style.display="block"; 
	GradientShow(layerMenuName);
}

function GradientShow(layerMenuName){
	if (layerMenuName==null)
		return;
	document.getElementById(layerMenuName).filters.alpha.opacity+=intInterval; 
   	if (document.getElementById(layerMenuName).filters.alpha.opacity<100) {
		eval('setTimeout("GradientShow(\'' + layerMenuName + '\')",intDelay); ');
   	}
} 

function GradientClose(layerMenuName){ 
	if (layerMenuName==null)
		return;
	document.getElementById(layerMenuName).filters.alpha.opacity-=intInterval; 
	if (document.getElementById(layerMenuName).filters.alpha.opacity>0) { 
		eval('setTimeout("GradientClose(\'' + layerMenuName + '\')",intDelay); ');
	} else { 
		document.getElementById(layerMenuName).style.display="none";
	} 
} 

function mergeOpinionL(t1,t2,t){
	document.getElementById(t1).value= t2+" "+document.getElementById(t1).value;
	GradientClose(t);
}

function mergeOpinionR(t1,t2,t){
	document.getElementById(t1).value= document.getElementById(t1).value+" "+t2;
	GradientClose(t);
}

function mov(layerMenuName){ 
	var menu = document.getElementById(layerMenuName);
	var srcObj = event.srcElement;
    //divid.style.visibility = 'visible';
    menu.style.left=document.body.scrollLeft + event.clientX;
    menu.style.top=document.body.scrollTop + event.clientY;
    menu.style.width = "180px";
}

function doConfirm(msg, needConfirm) {
	if (needConfirm!=undefined && !needConfirm)
		return true;
	return confirm(msg);
}

//选择人员(选择配置编号)
function selectRY(tj){
	window.open('/goa/product/operform/operform.do?method=changeAction&change=jkryxz&docid='+tj,'selectpeople','scrollbars=yes,resizable=yes,width=1180,height=600,left=100,top=60');
}

//选择部门(页面接收返回值的字段名)
function selectBM(t){
	var returncont="";
	var zhi = showModalDialog("/goa/product/sel-form/selectform.do?method=changeAction&change=gsxz", "",  "dialogWidth=1180px;dialogHeight=600px;dialogLeft=100px;dialogTop=100px;status=no;");
 
       if (typeof(zhi)!= "undefined") {
          returncont=zhi;
       }
       
  	  if(zhi){
               document.getElementById(t).value = returncont;
          }else{
               document.getElementById(t).value = returncont;
          }
	
}

//选择岗位(选择配置编号，页面中原有岗位值带入选择页面)
function selectGW(selcode,selcol){
  var popwindow_height=315;
  var popwindow_width=600;
  var popwindow_left=(screen.availWidth-700)/2;
  var popwindow_top=(screen.availHeight-440)/2;
  var zhi = document.getElementById(selcol).value;
  var seloldzhi=zhi.replace(new RegExp(',','g'),';');
  parent.openManageWindow = self.open("/goa/product/sel-form/selectform.do?method=getSelFormfxAll&docid="+selcode+"&anniu=true&zhi="+seloldzhi, "managePage", "directories=no,toolbar=no,menubar=no,scrollbars=yes,width=830,height=400,left="+popwindow_left+",top="+popwindow_top);

}

function selectGS(t){

}